Page({
  data: {
    paramData: {},
    width: '',
    height: '',
    // 动画时长
    delay: 0,
    length: 0,
    // 动画样式
    captionsClass: ''
  },
  onLoad: function () {

    const {windowHeight, windowWidth} = wx.getSystemInfoSync()

    wx.getStorage({
      key: 'captionsData',
      success: (res) => {

        this.setData({
          paramData: JSON.parse(res.data),
          width: windowWidth,
          height: windowHeight
        })


        wx.createSelectorQuery().select('#captions').boundingClientRect().exec(res => {

          const length = res[0].height

          if (length < this.data.height) {
            this.setData({
              captionsClass: this.data.paramData.level ? 'level-not-animation' : 'vertical-not-animation'
            })
            return
          }


          this.setData({
            delay: Math.ceil(length / this.data.paramData.velocity),
            length,
            captionsClass: this.data.paramData.level ? 'level-animation' : 'vertical-animation',
            height: this.data.height + 50
          })
        })


      }
    })


  },
});
